<?php
namespace app\api\controller;

use app\api\controller\BaseController;
use think\Db;

class Version extends BaseController
{
    public function set_user_password($old_password = "", $password = "")
    {
        // 获取用户信息
        $userInfo = getTokenInfo();
        if (!$userInfo) 
            return base_result(null, false, '10001', '请登录');
        $user_id = $userInfo->user_id;
        // $user_id = 1;

        if (!$password || !$old_password) {
            return base_result(null, false, 30002, "密码不能为空");
        }
        $user_info = Db::table('constructors')->where('id', $user_id)->where('password', md5($old_password))->value('id');
        if (!$user_info) {
            return base_result(null, false, null, '原密码错误');
        }
        $res = Db::table('constructors')->where('id', $user_id)->update(['password' => md5($password)]);
        if ($res) {
            return base_result(null, true);
        } else {
            return base_result(null, false, null, '操作错误');
        }
    }

    public function getVersion($phone_type = '')
    {
        if (empty($phone_type)) {
            return base_result(null, false, 30002, "手机类型参数不正确");
        }
        $where['phone_type'] = $phone_type;
        $res  = Db::table('media_version')->where($where)->order('release_time desc')->find(); 
        return base_result($res, true);
    }  






}
